home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / tde31.zip / CRITERR.C < prev    next >
C/C++ Source or Header  |  1993-08-29  |  6KB  |  192 lines

  1. /*
  2.  * Instead of the Abort, Retry, Ignore thing, let's try to handle critical
  3.  * errors within tde.  Give the user some indication of the critical error
  4.  * and then find out what the user wants to do.
  5.  *
  6.  * IMPORTANT:  This is a replacement for the standard DOS critical error
  7.  * handler.  Since DOS is not re-entrant, do not call any functions that,
  8.  * directly or indirectly, call DOS functions.  We are in some DOS function
  9.  * when a critical error occurs.  Using BIOS and direct hardware I/O
  10.  * functions, however, is allowed.
  11.  *
  12.  * The prototype for the critical error handler is
  13.  *
  14.  *            int  far crit_err_handler( void )
  15.  *
  16.  * The handler is explicitly declared as "far", because the assembly
  17.  * routine is hard coded for a "far" function.  See the bottom of
  18.  * int24.asm for more info.
  19.  *
  20.  * See (incidentally, these are the current references for MSDOS 6.0):
  21.  *
  22.  *   Microsoft Knowledge Base, "Action Taken on Abort, Retry, Ignore, Fail",
  23.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q67586,
  24.  *    Publication Date:  March 24, 1993.
  25.  *
  26.  *   Microsoft Knowledge Base, "Extended Error Code Information",
  27.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q74463,
  28.  *    Publication Date:  March 24, 1993.
  29.  *
  30.  *   Programmer's Reference Manual, Microsoft Corporation, Redmond,
  31.  *    Washington, 1986, Document No. 410630014-320-003-1285, pp. 1-20 thru
  32.  *    1-21, pp. 1-34 thru 1-38, p 1-99, pp. 1-121 thru 1-124, pp. 1-216 thru
  33.  *    1-218, pp. 2-1 thru 2-30.
  34.  *
  35.  *   Ray Duncan, _Advanced MS-DOS_, Microsoft Press, Redmond, Washington,
  36.  *    1986, ISBN 0-914845-77-2, pp 89-97, pp 130-133.
  37.  *
  38.  *
  39.  * New editor name:  TDE, the Thomson-Davis Editor.
  40.  * Author:           Frank Davis
  41.  * Date:             June 5, 1991, version 1.0
  42.  * Date:             July 29, 1991, version 1.1
  43.  * Date:             October 5, 1991, version 1.2
  44.  * Date:             January 20, 1992, version 1.3
  45.  * Date:             February 17, 1992, version 1.4
  46.  * Date:             April 1, 1992, version 1.5
  47.  * Date:             June 5, 1992, version 2.0
  48.  * Date:             October 31, 1992, version 2.1
  49.  * Date:             April 1, 1993, version 2.2
  50.  * Date:             June 5, 1993, version 3.0
  51.  * Date:             August 29, 1993, version 3.1
  52.  *
  53.  * This code is released into the public domain, Frank Davis.
  54.  *    You may distribute it freely.
  55.  */
  56.  
  57. #include "tdestr.h"
  58. #include "common.h"
  59. #include "tdefunc.h"
  60. #include "criterr.h"
  61.  
  62. /*
  63.  * Save the area of the screen that will display the Critical
  64.  * Error info.  CEH_WIDTH and CEH_HEIGHT are the dimensions of critical
  65.  * error screen in criterr.h.   CEH_OFFSET is the offset into the screen
  66.  * refresh buffer.  Let the compiler calculate the offset, 'cause the offset
  67.  * don't change anyway.
  68.  */
  69. #define CEH_ROW         5
  70. #define CEH_COL         6
  71. #define CEH_WIDTH       69
  72. #define CEH_HEIGHT      15
  73.  
  74. #define CEH_OFFSET      ((CEH_ROW * 160) + (CEH_COL * 2))
  75.  
  76. #define NEXT_LINE       160
  77.  
  78.  
  79. /*
  80.  * buffer for ceh info screen.  make this an int array because we
  81.  * need to save character and attribute.
  82.  */
  83. int ceh_buffer[CEH_HEIGHT][CEH_WIDTH];
  84.  
  85.  
  86. /*
  87.  * Name:    crit_err_handler
  88.  * Purpose: Show user something is wrong and get a response
  89.  * Date:    April 1, 1992
  90.  */
  91. int  far crit_err_handler( void )
  92. {
  93. int  rc;
  94. int  c;
  95.  
  96.    save_area( (char far *)ceh_buffer );
  97.    show_error_screen( CEH_ROW, CEH_COL );
  98.    xygoto( 60, 17 );
  99.    do
  100.       c = getkey( );
  101.    while (c != 'Q' && c != 'q' && c != 'R' && c != 'r' && c != 'A' && c != 'a');
  102.    switch ( c ) {
  103.       case 'A':
  104.       case 'a':
  105.          rc = ABORT;
  106.          break;
  107.       case 'Q':
  108.       case 'q':
  109.          rc = FAIL;
  110.          break;
  111.       case 'R':
  112.       case 'r':
  113.       default :
  114.          rc = RETRY;
  115.          break;
  116.    }
  117.    restore_area( (char far *)ceh_buffer );
  118.    return( rc );
  119. }
  120.  
  121.  
  122. /*
  123.  * Name:    show_error_screen
  124.  * Purpose: Display error screen in window
  125.  * Date:    April 1, 1992
  126.  * Passed:  row: line to display ceh screen
  127.  *          col: column to begin display ceh screen
  128.  */
  129. void show_error_screen( int row, int col )
  130. {
  131. char **p;
  132.  
  133.    for (p=criterr_screen; *p != NULL; p++, row++)
  134.       s_output( *p, row, col, g_display.help_color );
  135.    s_output( error_code[ceh.code],    8, 23, g_display.help_color );
  136.    s_output( operation[ceh.rw],       9, 23, g_display.help_color );
  137.    if (ceh.dattr == 0)
  138.       c_output( ceh.drive + 'a',     23, 10, g_display.help_color );
  139.    else
  140.       s_output( critt1,              10, 23, g_display.help_color );
  141.    s_output( ext_err[ceh.extended],  11, 23, g_display.help_color );
  142.    s_output( error_class[ceh.class], 12, 23, g_display.help_color );
  143.    s_output( locus[ceh.locus],       13, 23, g_display.help_color );
  144.    s_output( device_type[ceh.dattr], 14, 23, g_display.help_color );
  145.    s_output( ceh.dattr == 0 ? critt1 : ceh.dname,
  146.                                      15, 23, g_display.help_color );
  147. }
  148.  
  149.  
  150. /*
  151.  * Name:    save_area
  152.  * Purpose: save a region of the screen
  153.  * Date:    April 1, 1992
  154.  * Passed:  dest: pointer to buffer for contents of screen under ceh
  155.  * Notes:   this function does not check for snow.  the source is the screen
  156.  *             and the destination is the buffer.
  157.  */
  158. void save_area( char far *dest )
  159. {
  160. char far *source;
  161. register int hgt;
  162.  
  163.    source = (char far *)g_display.display_address + CEH_OFFSET;
  164.    for (hgt=CEH_HEIGHT; hgt; hgt--) {
  165.       _fmemcpy( dest, source, CEH_WIDTH*2 );
  166.       source += NEXT_LINE;
  167.       dest += (CEH_WIDTH*2);
  168.    }
  169. }
  170.  
  171.  
  172. /*
  173.  * Name:    restore_area
  174.  * Purpose: restore a region of the screen
  175.  * Date:    April 1, 1992
  176.  * Passed:  source: pointer to buffer for contents of screen under ceh
  177.  * Notes:   this function does not check for snow.  the source is the buffer
  178.  *             and the destination is the screen.
  179.  */
  180. void restore_area( char far *source )
  181. {
  182. char far *dest;
  183. register int hgt;
  184.  
  185.    dest = (char far *)g_display.display_address + CEH_OFFSET;
  186.    for (hgt=CEH_HEIGHT; hgt; hgt--) {
  187.       _fmemcpy( dest, source, CEH_WIDTH*2 );
  188.       dest += NEXT_LINE;
  189.       source += (CEH_WIDTH*2);
  190.    }
  191. }
  192.